package com.usian.admin.controller;

import com.usian.admin.service.AdchannelService;
import com.usian.api.admin.ChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理" ,tags = "channel", description = "频道管理API")
public class AdchannelController implements ChannelControllerApi {

    @Autowired
    private AdchannelService adchannelService;

    /**
     * 频道分页方法
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "dto",type = "ChannelDto",value = "查询字段")
    public ResponseResult findPage(@RequestBody ChannelDto dto) {
        return adchannelService.findPage(dto);
    }

    /**
     * 频道添加方法
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    @Override
    @ApiOperation(value = "新增频道信息",notes = "像频道列表添加数据")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "添加字段")
    public ResponseResult AddAdchannel(@RequestBody AdChannel adChannel) {
        return adchannelService.addChannel(adChannel);
    }

    /**
     * 频道修改方法
     *
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    @Override
    @ApiOperation(value = "修改频道信息",notes = "修改频道列表中数据")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "修改字段")
    public ResponseResult updateAdchannel(@RequestBody AdChannel adChannel) {
        return adchannelService.updateAdchannel(adChannel);
    }

    /**
     * 频道删除方法
     *
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @Override
    @ApiOperation(value = "删除频道信息",notes = "删除频道列表中数据")
    @ApiImplicitParam(name = "id",type = "Integer",value = "删除字段")
    public ResponseResult delById(@PathVariable Integer id) {
        return adchannelService.delById(id);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult channels() {
        List<AdChannel> list = adchannelService.list();
        return ResponseResult.okResult(list);
    }


}
